import { Body, Controller, Get, Post } from '@nestjs/common';
import { CategoryService } from 'src/services/category/category.service';
import { Category } from 'src/types/category.interface';
import { HttpResponse } from 'src/types/http_response.interface';

@Controller('categories')
export class CategoryController {
  constructor(private readonly categoryService: CategoryService) {}
  @Get()
  async findAllActive(): Promise<HttpResponse<Category[]>> {
    const data = await this.categoryService.find({ isActive: true });
    return {
      success: true,
      message: 'All active categories retrieved successfully',
      data,
    };
  }
  @Post()
  async create(
    @Body() createCategoryDTO: Category | Category[]
  ): Promise<HttpResponse<Category | Category[]>> {
    const data = await this.categoryService.create(createCategoryDTO);
    return {
      success: true,
      message: 'Category created successfully',
      data,
    };
  }
  @Get('products')
  async findCategoriesWithProducts(): Promise<HttpResponse<Category[]>> {
    const data = await this.categoryService.findCategoriesWithProducts();
    return {
      success: true,
      message: 'All active categories retrieved successfully',
      data,
    };
  }
}
